package com.example.mystarterusingapp;

import com.example.myweirdfunction.MyWeirdBean;
import org.springframework.beans.factory.BeanFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@SpringBootApplication
@RestController
public class MyStarterUsingAppApplication {

    public static void main(String[] args) {
        SpringApplication.run(MyStarterUsingAppApplication.class, args);
    }

    @Autowired
    private BeanFactory beanFactory;

    @Autowired
    private MyWeirdBean myWeirdBean;

    //    虽然autoconfigure有这个配置, 但是starter没有依赖, 所以无法使用
    //    @Autowired
    //    private OtherBean otherBean;

    @RequestMapping("bean1")
    public Object bean1() {
        return myWeirdBean.nonsenseFunction();
    }

    @RequestMapping("bean2")
    public Object bean2() {
        return beanFactory.getBean("bean2");
    }
}
